package com.carryking.smart.rpc.netty;

import com.carryking.smart.rpc.netty.channel.ServerChannel;
import com.carryking.smart.rpc.netty.code.RequestEntityDecoder;
import com.carryking.smart.rpc.netty.code.ResponseEntityEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;


/**
 * Created by jincarry on 2018/1/10.
 */
public class ProviderChannelInitializer extends ChannelInitializer<SocketChannel>{

    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024*1024, 0, 4,0,4));
        ch.pipeline().addLast(new LengthFieldPrepender(4));
        ch.pipeline().addLast(new RequestEntityDecoder());
        ch.pipeline().addLast(new ResponseEntityEncoder());

        //test
        ch.pipeline().addLast(new ServerChannel());
    }
}
